import BaseObj from "./BaseObj";
import Player from "./Player";

export default class ObjContainer{
    public static container:Set<BaseObj> = new Set()
    public static players:Map<string,BaseObj> = new Map()

    public static addObj(obj:BaseObj){
        ObjContainer.container.add(obj)
        if(obj instanceof Player){
            ObjContainer.players.set(obj.userId,obj)
        }

    }

    public static removeObj(obj:BaseObj){
        ObjContainer.container.delete(obj)
        if(obj instanceof Player){
            ObjContainer.players.delete(obj.userId)
        }
    }

    public static getPlayer(userId:string){
        return ObjContainer.players.get(userId)
    }

    // public static getObjs<T extends Function>():T[]{
    //     let result:T[] = []
    //     for (let index = 0; index < ObjContainer.container.size; index++) {
    //        let obj =  ObjContainer.container[index]
    //         if(typeof obj === typeof T ){
    //             result.push(obj)
    //         }
    //     }
    //     return result
    // }
}